<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/layout.xhtml">
	<ui:define name="contentPart">
		<h:form id="formId">
		
			<script type="text/javascript">
				function handleMessage(facesmessage) {	
					window.location = location.href;
					#{standardAction.load}
				}
			</script>
		
			<p:socket onMessage="handleMessage" channel="/notificationsChannel" />
			<h:outputText value="#{standardAction.welcomemessage}" />

			<p:panel id="rpnl" header="Source file(s)">
				<h:outputText id="fileValue"
					value="#{treeBean.selectedNode.label}" />
			</p:panel>

			<h:panelGrid id="clientsPG" style="text-align:center"
					rendered="#{!(fn:length(standardAction.clientDBs) eq 0)}">
				<ui:repeat id="repeater" value="#{standardAction.clientDBs}"
					var="db" varStatus="status">
					<h:panelGrid columns="2" id="clientPG">
						<h:panelGrid columns="1" style="text-align:center">
							<h:graphicImage value="/resources/css/img/rss.png" style="border:0"
								id="clientImg" />
							<h:outputText value="#{db.name}"
								style="font-size:14px;color:black;font-weight:bold" />
						</h:panelGrid>

						<h:panelGrid columns="9">
							<p:commandButton styleClass="buttonTable" icon="buttonPlay"
								action="#{standardAction.streamFile}" update=":growl"
								style="width:100%" title="Start to stream selected file(s)">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonPause"
								action="#{standardAction.suspendStream}"
								update=":growl :formId:clientsPG" style="width:100%"
								rendered="#{!(db.resumeVisible)}" title="Suspend current stream">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonResume"
								title="Resume current stream"
								action="#{standardAction.resumeStream}"
								update=":formId:clientsPG" style="width:100%"
								rendered="#{(db.resumeVisible)}">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonPrevious"
								action="#{standardAction.playPrevious}" update=":growl"
								style="width:100%" title="Stream previous file">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonNext"
								action="#{standardAction.playNext}" update=":growl"
								style="width:100%" title="Stream next file">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonStop"
								action="#{standardAction.stopStream}" update=":growl"
								style="width:100%">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							
							<p:commandButton styleClass="buttonTable" icon="buttonRepeatOn"
								action="#{standardAction.repeatStream}"
								update=":growl :formId:clientsPG" style="width:100%"
								rendered="#{!(db.client.srv.repeatMode)}" title="Repeat mode on">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonRepeatOff"
								action="#{standardAction.repeatStream}"
								update=":growl :formId:clientsPG" style="width:100%"
								rendered="#{(db.client.srv.repeatMode)}" title="Repeat mode off">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							
							<p:commandButton styleClass="buttonTable" icon="buttonShuffleOn"
								action="#{standardAction.shuffleStream}"
								update=":growl :formId:clientsPG" style="width:100%"
								rendered="#{!(db.client.srv.shuffle)}" title="Shuffle mode on">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							<p:commandButton styleClass="buttonTable" icon="buttonShuffleOff"
								action="#{standardAction.shuffleStream}"
								update=":growl :formId:clientsPG" style="width:100%"
								rendered="#{(db.client.srv.shuffle)}" title="Shuffle mode off">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							
							<p:commandButton action="#{standardAction.addToPlayList}" value="Add"
								update=":growl :formId:clientsPG" style="width:100%"
								title="Add to play list">
								<f:setPropertyActionListener
									target="#{standardAction.selectedClientDB}" value="#{db}" />
							</p:commandButton>
							
							<p:commandButton
									actionListener="#{standardAction.emptyPlayList}" value="Empty"
									update=":growl :formId:clientsPG" >
									<f:setPropertyActionListener
										target="#{standardAction.selectedClientDB}" value="#{db}" />	
							</p:commandButton>
						</h:panelGrid>

						

						<h:outputText value="Current file: "/>
						<h:outputText value="#{db.client.currentFilePath}"/>
					</h:panelGrid>

					<h:panelGrid id="playListPG" style="text-align:center">
						<p:dataTable value="#{db.playList}" var="file" scrollable="true"
							scrollHeight="150" style="width:900px" scrollWidth="920"
							rowStyleClass="#{file.absolutePath eq db.client.currentFilePath ? 'yellowRow' : 'whiteRow'}">

							<p:column sortBy="#{file.name}" headerText="Name"
								footerText="Name" width="250">
								<h:outputText value="#{file.name}"
									title="#{file.absolutePath} = #{file.absolutePath eq db.client.currentFilePath}" />
							</p:column>

							<p:column sortBy="#{file.name}" headerText="Path"
								footerText="Path" width="350">
								<h:outputText value="#{file.absolutePath}" />
							</p:column>

							<p:column width="18">
								<p:commandButton action="#{standardAction.playSelectedResource}"
									styleClass="buttonTable16" icon="buttonPlayTable"
									update=":formId:clientsPG" title="Play selected ressource">
									<f:setPropertyActionListener
										target="#{standardAction.selectedResource}" value="#{file}" />
									<f:setPropertyActionListener
										target="#{standardAction.selectedClientDB}" value="#{db}" />
								</p:commandButton>
							</p:column>

							<p:column width="18">
								<p:commandButton
									action="#{standardAction.removeSelectedResource}"
									styleClass="buttonTable16" icon="buttonRemoveTable"
									title="Remove from play list" update=":formId:clientsPG">
									<f:setPropertyActionListener
										target="#{standardAction.selectedResource}" value="#{file}" />
									<f:setPropertyActionListener
										target="#{standardAction.selectedClientDB}" value="#{db}" />
								</p:commandButton>
							</p:column>
						</p:dataTable>
					</h:panelGrid>
				</ui:repeat>
			</h:panelGrid>
		</h:form>
	</ui:define>
</ui:composition>
</html>